<?php

namespace app\admin\controller;

use think\Controller;
use think\Session;
use think\Request;
use think\Db;

class BaseController extends Controller
{
    public function _initialize()
    {
        $staff = Session::get('staff');
        if(empty($staff)){
            $url = url('admin/login/login');
            echo '<script>alert("亲,你已退出登陆");location="'.$url.'"</script>';
            exit;
        }
//        if($staff['name'] == 'admin'){
//            //$this->assign('staff',$staff);
//            $this->assign('tag','admin');
//            return;
//        }

//        //获取当前控制器和方法名
//        $controller = $this->getLowerController();
//        $action = $this->getLowerAction();
//        //获取节点列表
//        $nodeList = Session::get('nodeList');
//        //如果当前控制器不在节点列表,表示没有权限
//        if(empty($nodeList[$controller]) || !in_array($action,$nodeList[$controller])){
//            //$this->error("抱歉,你没有此操作权限！");
//            exit();
//        }
        $this->assign('staff',$staff);
    }




    protected function getLowerController(){
        return strtolower(Request::instance()->controller());
    }

    protected function getLowerAction()
    {
        return strtolower(Request::instance()->action());
    }


}
